package com.stg.service.impl;

import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.stg.bean.Assn;
import com.stg.bean.Student;
import com.stg.dao.AssnDao;
import com.stg.service.AssnService;
import com.stg.service.StudentService;
@Service("assnService")
public class AssnServiceImpl implements AssnService {

	@Resource
	private AssnDao assnDao;
	
	@Resource
	private StudentService studentService;
	
	@Override
	/**
	 * 创建社团
	 */
	public void createAssn(Assn assn) {
		assnDao.createAssn(assn);
	}

	/**
	 * 删除社团
	 */
	@Override
	public void deleteAssn(String assnName) {
		assnDao.deleteAssn(assnName);
	}

	/**
	 * 更新社团信息
	 */
	@Override
	public void updateAssn(Assn assn) {
		assnDao.updateAssn(assn);
	}

	/**
	 * 找到本社团中所有成员
	 */
	@Override
	public List<Student> findAllStudentByAssn(Long assnId) {
		List<String> studentIdList = assnDao.findAllStudentIdByAssn(assnId);
		List<Student> studentList = new ArrayList<Student>();
		for (String studentId : studentIdList) {
			Student student = studentService.findStudentById(studentId);
			studentList.add(student);
		}
		return studentList;
	}

	/**
	 * 通过社团id找到社团信息
	 */
	@Override
	public Assn findAssnById(Long id) {
		return assnDao.findAssnById(id);
	}

	/**
	 * 获取报名学生信息
	 */
	@Override
	public List<Student> findAllStudentPendingByAssn(Long assnId) {
		List<String> studentIdList = assnDao.findAllStudentIdPendingByAssn(assnId);
		List<Student> studentList = new ArrayList<Student>();
		for (String studentId : studentIdList) {
			Student student = studentService.findStudentById(studentId);
			studentList.add(student);
		}
		return studentList;
	}

	/**
	 * 录取学生
	 * 暂未实现
	 */
	@Override
	public void updateStudentPended(List<Student> studentList) {
		assnDao.updateStudentPended(studentList);
	}

}
